﻿Imports Negocio
Imports Excepciones
Imports Servicios
'TODO: Patron Template Method -> Clase Concreta
Public Class LoginForm
    Inherits Base

    Protected Overrides Sub PreLoad()
        Me.Icon = Icon.FromHandle(Global.SIPRO.My.Resources.Resources.key.GetHicon())
    End Sub

    Private Sub LoginForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Init()
    End Sub

    Private Sub Init()
        Try
            Dim idis As List(Of Idioma) = GesIdiomas.Consultar(Nothing)
            cbIdiomas.DataSource = idis
            cbIdiomas.SelectedIndex = 0
        Catch ex As Exception
            My.Application.HandlerException(ex)
            Me.Close()
        End Try
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        If MyBase.ValidateForm() Then
            Me.Close()
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub cbIdiomas_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cbIdiomas.SelectedIndexChanged
        MyBase.ResetErrorUI(cbIdiomas)
        If TypeOf cbIdiomas.SelectedItem Is Idioma Then
            Dim idi As New Idioma()
            idi = DirectCast(cbIdiomas.SelectedItem, Idioma)
            Try
                Current.Idioma = idi
                My.Application.ReloadLanguage()
            Catch ex As Exception
                MyBase.SetErrorUI(cbIdiomas, New LanguageFileNotFoundException())
            End Try
        Else
            MyBase.SetErrorUI(cbIdiomas, New ItemSelectRequiredException())
        End If
    End Sub

#Region "Validaciones"

    'Private Sub txtUsername_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtUsername.Validating

    '    MyBase.ResetErrorUI(sender)
    '    Try
    '        Validations.Required(txtUsername.Text)
    '        Validations.NotWhiteSpace(txtUsername.Text)
    '    Catch ex As CustomException
    '        e.Cancel = True
    '        MyBase.SetErrorUI(sender, ex)
    '    End Try

    'End Sub

    'Private Sub txtPassword_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtPassword.Validating

    '    MyBase.ResetErrorUI(sender)
    '    Try
    '        Validations.Required(txtPassword.Text)
    '        Validations.NotWhiteSpace(txtPassword.Text)
    '    Catch ex As CustomException
    '        e.Cancel = True
    '        MyBase.SetErrorUI(sender, ex)
    '    End Try

    'End Sub
#End Region

End Class
